// Package mgmt
// @Author: zhengqi Wu
// @Description:
// @Version: 1.0.0
// @Date: 2021/4/29 10:04 上午
// @Copyright: MIN-Group；国家重大科技基础设施——未来网络北大实验室；深圳市信息论与未来网络重点实验室
//
const {CommandExecutor} = require("./CommandExecutor");

class MIRController{
    constructor() {
        this.logicFaceBuilder = null
        this.keyChain = null
        this.autoShutdown = false
    }

    /**
     * PrepareCommandExecutor 构造一个命令执行器用来执行命令
     * @param command
     * @return {CommandExecutor}
     */
    prepareCommandExecutor(command){
        let logicface = (this.logicFaceBuilder)()

        let commandExecutor = new CommandExecutor()
        commandExecutor.init(command, logicface)
        commandExecutor.autoShutdown = this.autoShutdown
        commandExecutor.keyChain = this.keyChain
        return commandExecutor
    }
}

/**
 * CreateMIRController 创建一个 MIRController
 * @param faceBuilder
 * @param autoShutdown
 * @param keychain
 * @return {MIRController}
 */
function createMIRController(faceBuilder, autoShutdown, keychain){
    let mirController = new MIRController()
    // 记录 LogicFace 构造器，之后发起命令时，可以使用这个构造器构造一个逻辑接口发起命令请求
    mirController.logicFaceBuilder = faceBuilder
    mirController.keyChain = keychain
    mirController.autoShutdown = autoShutdown
    return mirController
}

module.exports = {
    createMIRController: createMIRController,
    MIRController: MIRController
}